import Blockly from 'blockly/core'
import 'blockly/python_compressed'
import 'blockly/blockly_compressed'
import 'blockly/blocks_compressed'

Blockly.Blocks.function_pow = {
  init: function () {
    this.appendValueInput('A').setCheck('Number').appendField('pow(')
    this.appendValueInput('B').setCheck('Number').appendField(',')
    this.appendDummyInput().appendField(')')
    this.setInputsInline(true)
    this.setOutput(true, null)
    this.setColour(230)
    this.setTooltip('')
    this.setHelpUrl('')
  }
}

Blockly.Python.function_pow = function (block) {
  const valueA = Blockly.Python.valueToCode(
    block,
    'A',
    Blockly.Python.ORDER_ATOMIC
  )
  const valueB = Blockly.Python.valueToCode(
    block,
    'B',
    Blockly.Python.ORDER_ATOMIC
  )
  const code = 'pow(' + valueA + ',' + valueB + ')'
  return [code, Blockly.Python.ORDER_NONE]
}

// math_float
Blockly.Blocks.math_float = {
  init: function () {
    this.appendValueInput('NAME').setCheck(null).appendField('float(')
    this.appendDummyInput().appendField(')')
    this.setInputsInline(true)
    this.setOutput(true, null)
    this.setColour(15)
    this.setTooltip('')
    this.setHelpUrl('')
  }
}

Blockly.Python.math_float = function (block) {
  const valueName = Blockly.Python.valueToCode(
    block,
    'NAME',
    Blockly.Python.ORDER_ATOMIC
  )
  const code = 'float(' + valueName + ')'
  return [code, Blockly.Python.ORDER_NONE]
}
// 类型运算符

Blockly.Blocks.math_instanceof = {
  init: function () {
    this.appendValueInput('A').setCheck(null)
    this.appendValueInput('B').setCheck(null).appendField('|')
    this.setInputsInline(true)
    this.setOutput(true, null)
    this.setColour(230)
    this.setTooltip('')
    this.setHelpUrl('')
  }
}

Blockly.Python.math_instanceof = function (block) {
  const valueA = Blockly.Python.valueToCode(
    block,
    'A',
    Blockly.Python.ORDER_ATOMIC
  )
  const valueB = Blockly.Python.valueToCode(
    block,
    'B',
    Blockly.Python.ORDER_ATOMIC
  )
  const code = valueA + '|' + valueB
  return [code, Blockly.Python.ORDER_NONE]
}

// math_walrusexpression
Blockly.Blocks.math_walrusexpression = {
  init: function () {
    this.appendValueInput('left').setCheck(null)
    this.appendDummyInput().appendField(':=')
    this.appendValueInput('right').setCheck(null)
    this.setInputsInline(true)
    this.setOutput(true, null)
    this.setColour(230)
    this.setTooltip('')
    this.setHelpUrl('')
  }
}

Blockly.Python.math_walrusexpression = function (block) {
  const valueLeft = Blockly.Python.valueToCode(
    block,
    'left',
    Blockly.Python.ORDER_ATOMIC
  )
  const valueRight = Blockly.Python.valueToCode(
    block,
    'right',
    Blockly.Python.ORDER_ATOMIC
  )
  const code = valueLeft + ' := ' + valueRight
  return [code, Blockly.Python.ORDER_NONE]
}

export default Blockly
